package com.xtayfjpk.jersey.test.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

import com.xtayfjpk.jersey.test.service.domain.User;

@Path("/userservice")
public class UserService {
	static Map<Integer, User> userMap = new HashMap<Integer, User>();

	static {
		User user1 = new User(1, 25, "张三");
		User user2 = new User(2, 29, "李四");
		User user3 = new User(3, 36, "王五");
		userMap.put(1, user1);
		userMap.put(2, user2);
		userMap.put(3, user3);
	}


	@GET
	@Path("/user/{id}") // 具体服务的路径, id是入参
	@Produces("application/json") // 返回的格式
	public User getById(@PathParam("id") Integer id) {
		return userMap.get(id);
	}

	@GET
	@Path("/users") // 具体服务的路径, id是入参
	@Produces("application/json") // 返回的格式
	public List<User> getUsers() {
		return new ArrayList<User>(userMap.values());
	}
}
